﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Newtonsoft.Json;
using System.Web.Services;
using RN.ERP.Web.ModelService;

namespace RN.ERP.Web.Exam
{
    public partial class BmKMList : BasePage
    {
        private string pageCode = "KM";
        private string page = "BmKMList.aspx";
        private string AppID
        {
            get
            {
                return HttpContext.Current.Application[ApplicationConstant.APPLICATION_ID].ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            RadGrid1.AllowCustomPaging = true;
            int pageCount = RadGrid1.CurrentPageIndex;
            int pageSize = RadGrid1.PageSize;
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                int count = 0;
                ////获取科目列表
                var exam = JsonConvert.DeserializeObject<List<ModelService.Exam_KM>>(client.GetExamKMList
                    (pageCode, UserInfo.RoleId, page, AppID, null, pageCount + 1, pageSize, out count));
                if (exam != null)
                {
                    RadGrid1.VirtualItemCount = count;
                    RadGrid1.DataSource = exam;
                }
            }
        }

        [WebMethod]
        public static string DelKM(object id)
        {
            string ret = null;
            int kmId = 0;
            int.TryParse(id.ToString(), out kmId);
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                OperationResult result = new OperationResult();
                result = JsonConvert.DeserializeObject<ModelService.OperationResult>(client.DeleteExamKM(kmId));
                ret = JsonConvert.SerializeObject(new { Message = result.Message });
            }
            return ret;
        }

        /// <summary>
        /// 根据期次id获取期次Title
        /// </summary>
        /// <param name="qcId"></param>
        /// <returns></returns>
        public string GetQCTitle(object qcId)
        {
            string qc = string.Empty;
            int id = 0;
            int.TryParse(qcId.ToString(), out id);
            using (PersonService.PersonServiceClient client = new PersonService.PersonServiceClient())
            {
                var exam = JsonConvert.DeserializeObject<ModelService.Exam_QC>(client.GetExamQC(id));
                qc = exam.Title;
            }
            return qc;
        }
    }
}